/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.loja.view.component.composition;

import br.com.loja.model.service.exception.ServiceException;
import br.com.loja.util.reflection.ReflectionUtil;
import br.com.loja.view.component.factory.ViewHadler;
import br.com.loja.view.swing.PanelEntityEditor;

/**
 *
 * @author DavidLuiz
 */
public class EntityToOne<T> extends PanelEntityEditor<T> implements ViewHadler<T> {

    private final Class<T> entityClass;

    public EntityToOne(Class<T> entityClass) throws ServiceException {
        super(entityClass);
        this.entityClass = entityClass;
    }

    @Override
    public void setValueModel(T value) {
        setModel(value);
    }

    @Override
    public T getValueModel() {
        T entity = (T) ReflectionUtil.getBeanInstance(entityClass.getName());
        return getModel(entity);
    }

}
